<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Common\Model;
use Think\Model;


class NoticeModel extends Model{

    /* 用户模型自动完成 */
    protected $_auto = array(

        array('status', 0, self::MODEL_INSERT),
        array('update_time', 0, self::MODEL_INSERT),
        array('create_time', NOW_TIME, self::MODEL_INSERT),
    );




    public function automatic(){
        $model = M('Notice');
        $info = $model->where('status=0')->find();
        if(!empty($info)){
            $api = new \Common\Extend\Api\ApiClient();
            $api = $api->sms();
            if($info['is_mobile']==1){ //发送短信
                $api->mobile       = $info['mobile'];
                $api->content      = $info['content'];
            }elseif($info['is_mobile']==2){ //语音发送
                $api = new \Common\Extend\Api\ApiClient();
                $api = $api->sms();
                $api->mobile       = $info['mobile'];
                $api->content      = $info['content'];
                $api->type         = 'pt_audio';
            }
            $api->Send('get')->data();
            //查看是否推送微信消息
            if($info['is_weixin']==1){
                //执行微信代码

            }
            $model->where('id='.$info['id'])->save(['status'=>1,'update_time'=>NOW_TIME]);
        }

    }

    //发送微信模板
    //逾期模板 6zt9h0wrmv7ijn3VpaHJYAsSYfwC7PuPq-eE9HLwcXc
    /*
     * 1、逾期，2户提额成功，3还款银行卡内余额充，4打款成功，5今日到期，6即将到期，7已通过审核，8审核不通过，9，10
     */
    /*
        $data = [
        'title'=>'您好，您提交的借款审核不通过。',
        'money'=>'200.00',
        'day'=>'7',
        'content'=>'综合评分不足',
        ];
        D('Notice')->weixin(1,'om6dMvwUOc-6b_dEGSLTKysW8rQc',$data);
    */
      public function weixin($type,$uid,$data,$url=''){
          $info = M('ucenter_member')->where("id={$uid}")->field('openid,mobile')->find();
          $touser = $info['openid'];
          $mobile = $info['mobile'];
          $options = array(
              'token'     => 'alisytcom',   // 填写你设定的key
              'appid'     => 'wx78392779c32d9e0b',    // 填写高级调用功能的appid
              'appsecret' => '74863fe49126c79ce8112bced0745471' // 填写高级调用功能的密钥
          );
          $weixin = new \Common\Extend\Wechat\Wechat($options);
          switch ($type)
          {
             
                  case 10:
                  $template_id = 'hkHlUZAyF-oiSxCeVg2pY6a7SwFugfGBsAREfuckTIU';
                  $data2 = [
                      'first'=>['value'=>'扫码支付到账通知','color'=>'#FF0000'],//
                      'keyword1'=>['value'=>$data['money'].'元','color'=>''],
                      'keyword2'=>['value'=>$data['time'],'color'=>''],
                      'remark'=>['value'=>$data['remark'],'color'=>'#999'],
                  ];
                  break;

                  case 11:
                  $template_id = 'pjugiMPC9uMLbsJhZA5Ih91Hj-TjDBQOf4J15EzFUtU';
                  $data2 = [
                      'first'=>['value'=>'尊敬的'.$data['name'].'，您申请的提现金额已到账，请注意查收。','color'=>''],//
                      'keyword1'=>['value'=>$data['money'].'元','color'=>''],//
                      'keyword2'=>['value'=>$data['time'],'color'=>''],
                      'remark'=>['value'=>$data['remark'],'color'=>'#999'],
                  ];
                  break;

                  case 1:
                  $template_id = '0-cocI2RIgjiMOs3y3KASB5Fd0ozYKg6V96csveIIqE';
                  $data2 = [
                      'first'=>['value'=>$data['title'],'color'=>'#1C7DC1'],//
                      'keyword1'=>['value'=>$data['name'],'color'=>'#1C7DC1'],//
                      'keyword2'=>['value'=>$data['time'],'color'=>'#1C7DC1'],
                      'remark'=>['value'=>$data['remark'],'color'=>'#1C7DC1'],
                  ];
                  break;

                  case 2:
                  // 测试运维状态通知
                  $template_id = 'Ktsz8e60MvJ45ln9hC-UIsvbbHFO4GlSLZNd3YoCHm0';
                  $data2 = [
                      'first'=>['value'=>$data['title'],'color'=>'#1C7DC1'],//
                      'keyword1'=>['value'=>$data['name'],'color'=>'#1C7DC1'],//
                      'keyword2'=>['value'=>$data['status'],'color'=>'#1C7DC1'],
                      'keyword3'=>['value'=>$data['time'],'color'=>'#1C7DC1'],
                      'remark'=>['value'=>$data['remark'],'color'=>'#1C7DC1'],
                  ];
                  break;


              default:
          }
          $json = [
              'touser'      =>$touser,
              'template_id' => $template_id,
              'url'         =>$url,
              'topcolor'    =>'#FF0000',
              'data'=>$data2,
          ];//print_r(json_encode($json));exit;
          return $weixin->sendTemplateMessage($json);

      }



}
